package com.feihong.yw189.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.feihong.yw189.R;
import com.feihong.yw189.adapter.holder.HomePageFunMenuHolder;
import com.feihong.yw189.model.HomeFunList;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wangziheng
 * @ProjectName ywydt
 * @ClassName HomePageFunMenuAdapter
 * @package com.feihong.yw189.adapter
 * @data 2019/3/4 17:11
 * @Describe
 * @Change
 */
public class HomePageFunMenuAdapter extends RecyclerView.Adapter<HomePageFunMenuHolder> {
    private LayoutInflater mLayoutInflater;
    private List<HomeFunList> mFunDatas;
    private HomeFunItemClickListener mHomeFunItemClickListener;
    public HomePageFunMenuAdapter(Context context) {
        mLayoutInflater = LayoutInflater.from(context);
        mFunDatas = new ArrayList<>();
    }

    public void setData(List<HomeFunList> datas) {
        mFunDatas.clear();
        mFunDatas.addAll(datas);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public HomePageFunMenuHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new HomePageFunMenuHolder(mLayoutInflater.inflate(R.layout.adapter_item_home_page_fun_menu_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull HomePageFunMenuHolder holder, int position) {
        HomeFunList homeFunList = mFunDatas.get(position);
        holder.setData(homeFunList);
        if(mHomeFunItemClickListener != null){
            holder.itemView.setOnClickListener(v -> mHomeFunItemClickListener.setOnClickListener(homeFunList,position));
        }
    }

    public void setOnItemClick(HomeFunItemClickListener homeFunItemClickListener){
        mHomeFunItemClickListener = homeFunItemClickListener;
    }
    @Override
    public int getItemCount() {
        return mFunDatas.size();
    }
    public interface HomeFunItemClickListener{
        /**
         *
         * @param homeFunList
         * @param position
         */
        void setOnClickListener(HomeFunList homeFunList,int position);
    }
}
